package com.itstherules.jmsunit;

import org.junit.Assert;
import org.junit.Test;

public class XmlLoadersTest {

	static final String SEPARATOR = System.getProperty("line.separator");

	@Test
	public void canLoadXmlAsString() throws Exception {
		String reply = XmlLoaders.xml("test_xml");
		Assert.assertEquals(
				"<hobbit>" + SEPARATOR +
				"	<name>Bilbo Baggins</name>" + SEPARATOR +
				"	<age>12</age>" + SEPARATOR +
				"	<carries>The One Ring</carries>" + SEPARATOR +
				"</hobbit>", reply);
	}

	@Test(expected=IllegalArgumentException.class)
	public void cannotLoadXml() throws Exception {
		XmlLoaders.xml("invalid_test_xml");
	}

	
	@Test
	public void canLoadSchemaAsString() throws Exception {
		String reply = XmlLoaders.schema("test_schema");
		Assert.assertEquals(
				"<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>" + SEPARATOR +
				"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">" + SEPARATOR +
				"	<xs:element name=\"shiporder\">" + SEPARATOR +
				"		<xs:complexType>" + SEPARATOR +
				"			<xs:sequence>" + SEPARATOR +
				"				<xs:element name=\"orderperson\" type=\"xs:string\" />" + SEPARATOR +
				"			</xs:sequence>" + SEPARATOR +
				"			<xs:attribute name=\"orderid\" type=\"xs:string\"" + SEPARATOR +
				"				use=\"required\" />" + SEPARATOR +
				"		</xs:complexType>" + SEPARATOR +
				"	</xs:element>" + SEPARATOR +
				"</xs:schema>", reply);
	}

	@Test(expected=IllegalArgumentException.class)
	public void cannotLoadSchemaAsString() throws Exception {
		XmlLoaders.schema("i_dont_exist_so_please_dont_add_me");
	}
	

	@Test
	public void canLoadSoapAsString() throws Exception {
		String reply = XmlLoaders.soap("test_xml");
		Assert.assertEquals(
				"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" + SEPARATOR +
				"	<SOAP-ENV:Header/>" + SEPARATOR +
				"	<SOAP-ENV:Body>" + SEPARATOR +
				"<hobbit>" + SEPARATOR +
				"	<name>Bilbo Baggins</name>" + SEPARATOR +
				"	<age>12</age>" + SEPARATOR +
				"	<carries>The One Ring</carries>" + SEPARATOR +
				"</hobbit>" + SEPARATOR +
				"	</SOAP-ENV:Body>" + SEPARATOR +
				"</SOAP-ENV:Envelope>"
				, reply);
	}

	@Test(expected=IllegalArgumentException.class)
	public void cannotLoadSoap() throws Exception {
		XmlLoaders.soap("i_dont_exist_so_please_dont_add_me");
	}
	
}
